//package com.joshua.spring.datasource;
//
//import com.joshua.spring.context.DynamicDataSourceContextHolder;
//import com.joshua.spring.property.DatasourceProperties;
//import org.springframework.beans.factory.DisposableBean;
//import org.springframework.beans.factory.InitializingBean;
//
//import javax.sql.DataSource;
//import java.io.Closeable;
//import java.io.IOException;
//import java.util.concurrent.ConcurrentHashMap;
//
///**
// * projectName dragon-cloud
// * package com.joshua.spring.datasource
// * classname  DynamicRoutingDatasource
// * <p>
// * description 动态数据源
// * </p>
// *
// * @author <a href="mailto:joshualwork@163.com">joshua_liu</a>
// * @date 2020/11/14 15:24
// */
//public class DynamicRoutingDatasource extends AbstractRoutingDataSource implements InitializingBean, DisposableBean, Closeable {
//
//    /**
//     * 从配置中读取到的未初始化的数据源配置
//     */
//    private ConcurrentHashMap<String, DatasourceProperties> sourceDataSources;
//    /**
//     * 已经初始化过的数据源配置
//     */
//    private ConcurrentHashMap<String, DataSource> initializedDataSources;
//
//    @Override
//    public void close() throws IOException {
//
//    }
//
//    @Override
//    public void destroy() throws Exception {
//
//    }
//
//    @Override
//    protected DataSource determineDataSource() {
//        return getDatasource(DynamicDataSourceContextHolder.getCurrentDs());
//    }
//
//    @Override
//    public void afterPropertiesSet() throws Exception {
//        this.initializedDataSources = new ConcurrentHashMap<>();
//        this.sourceDataSources = new ConcurrentHashMap<>();
//    }
//
//    public DataSource getDatasource(String dsKey) {
//        if (initializedDataSources.containsKey(dsKey)) {
//            return initializedDataSources.get(dsKey);
//        } else if (sourceDataSources.containsKey(dsKey)) {
//            //TODO :初始化该数据源
//            //并将数据源放入初始化过的数据源中
////            initializedDataSources.put(dsKey, );
//        }
//        return this.targetDataSources.get(dsKey);
//    }
//}
